<template>
<!-- 单个商品的组件，等一下会被v-for -->
  <div id="CommodityItem" @click="myJump">
      <img :src="showImage" >
      <div class="commodity_title">
        <p>{{commodityItem.title}}</p>
        <span class="price">￥{{commodityItem.price}}</span>
        <span class="cfav">收藏：{{commodityItem.cfav}}</span>
      </div>

  </div>
</template>

<script>
export default {
  name: "CommodityItem",
  props: {
    commodityItem: {
      type: Object,
      defaults: {}
    },
  },
    methods:{
    //路由跳转
      myJump(){
        this.$router.push('/detail/'+this.commodityItem.iid);
      }
    },
  computed:{
    showImage(){
      return this.commodityItem.image || this.commodityItem.show.img;
    }
  }

}
</script>

<style scoped>
#CommodityItem{
  width: 45%;
  margin: 10px auto;
  text-align: center;
}
#CommodityItem img{
  width: 100%;
  border-radius: 5px;
}
.commodity_title p{
  margin-bottom: 7px;
  line-height: 20px;
  height: 40px;
  /*多行文字移出省略显示*/
  overflow: hidden;
  text-overflow: ellipsis;
  /*弹性伸缩盒子模型显示*/
  display: -webkit-box;
  /*限制在一块元素显示的文本的行数*/
  -webkit-line-clamp: 2;
  /*设置或索引伸缩对象的子元素的排列方式*/
  -webkit-box-orient: vertical;

}
.commodity_title .price{
  float: left;
  font-size: 17px;
  color: darkred;
  margin-left: 5px;
  line-height: 18px;
}
.commodity_title .cfav{
  float: right;
  font-size: 13px;
  line-height: 18px;
}
</style>
